using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

using DevExpress.XtraEditors;
using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Nodes;

namespace TCCT_CTC_CSDLDangVienV1
{
    /// <summary>
    /// User Interface class
    /// </summary>
    public static partial class UI
    {
        public static class Tree 
        {
            #region Property
		 
          

	        #endregion  Property
    
            public static void ApplyDefault(TreeList control)
            {
                ApplyDefault(control, false);
            }

            public static void ApplyDefault(TreeList control, bool enableAppearanceFocusedCell)
            {
                control.OptionsBehavior.Editable = false;
                Font font = control.Appearance.HeaderPanel.Font;
                control.Appearance.HeaderPanel.Font = new Font(font.FontFamily.Name, font.Size, FontStyle.Bold);
                control.OptionsSelection.EnableAppearanceFocusedCell = enableAppearanceFocusedCell;
            }
       
            public static long GetTreeLongValue(TreeList control,string fieldName)
            {
                return Convert.ToInt64 (control.Selection[0].GetValue(fieldName));
            }
            public static  string GetTreeStringValue(TreeList control, string fieldName)
            {
                return control.Selection[0].GetValue(fieldName).ToString();
            }
                
    //         #region UpdateActiveTreeNodesChild
    //        public static void UpdateActiveTreeNodesChild(string tableName,
    //        string IDColumnName,
    //        string parentIDColumnName,
    //        long ColumnID,
    //        string ActiveColumnName,
    //        bool IsActive)
    //         {
    //             int Active = 0;
    //             if (IsActive) Active = 1;


    //             string sql = "UPDATE " + tableName + " SET " + ActiveColumnName + " = " + Active + " WHERE " +
    //                          IDColumnName + " = " + ColumnID + "";
    //             AppDB.ExecuteNonQuery(sql);


    //             DataTable dtTem =
    //                 AppDB.ExecuteDataSet("SELECT * FROM " + tableName + " WHERE " + parentIDColumnName + " = " +
    //                                      ColumnID + "").Tables[0];
    //             if (dtTem.Rows.Count > 0)
    //             {
    //                 foreach (DataRow dr in dtTem.Rows)
    //                 {
    //                     UpdateActiveTreeNodesChild(tableName, IDColumnName, parentIDColumnName,
    //                                                (long) dr[IDColumnName], ActiveColumnName, IsActive);
    //                 }
    //             }
    //         }
    //#endregion UpdateActiveTreeNodesChild

            // #region UpdateParentNode

            //   public  static void UpdateActiveTreeNodesParent(string tableName,
            //string idColumnName,
            //string parentIDColumnName,
            //long parentID,
            //string ActiveColumnName,
            //bool IsActive)
            //{
            //int Active = 0;
            //if (IsActive) Active = 1;
            //// kiem tra xem no co cha ko
            //if(parentID > 0)  
            //{
            //    // lay ra tat ca anh em cua no. 

            //    DataTable dtTem = AppDB.ExecuteDataSet("Select * from " + tableName + " where " + parentIDColumnName + " = " + parentID + "").Tables[0];
            //    //neu ma co anh em kiem tra xem anh em co duoc check ko
            //    if (dtTem.Rows.Count > 0)
            //    {
            //        //neu co bat ki anh em nao duoc check thi cha no cung duoc check
            //        foreach (DataRow dr in dtTem.Rows)
            //        {
            //               if(dr["SuDung"].ToString().Equals("True"))
            //               {
            //                   //update cha no la true;
            //                   string sql = "Update " + tableName + " set " + ActiveColumnName + " = " + " True " + " where " + parentIDColumnName + " = " + dr[parentIDColumnName];
            //                   break;

            //               }
            //             //cap nhat de quy thang cha cua no 
            //         UpdateActiveTreeNodesParent(tableName,idColumnName,parentIDColumnName,(long)dr[parentIDColumnName],ActiveColumnName,IsActive);
            //        }
                   
            //    }
                
            //}
            // #endregion



            public static void SetTreeListSelectedNode(TreeList treeList, string fieldName,object value)
            {
                TreeListNode treeNode  = treeList.FindNodeByFieldValue(fieldName, value);
                treeList.SetFocusedNode(treeNode);
            }
           
        }
    }
}
